﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.Specialized;
using System.Reflection;
using System.ComponentModel;

namespace QlrrPrintService.Common
{
    public static class Util
    {
        public static NameValueCollection ConvertEnumDescriptionValue(Type enumType)
        {

            NameValueCollection nvc = new NameValueCollection();
            Type type = typeof(DescriptionAttribute);

            foreach (FieldInfo fi in enumType.GetFields())
            {
                object[] arr = fi.GetCustomAttributes(type, true);
                if (arr.Length > 0)
                {

                    nvc.Add(fi.Name, ((DescriptionAttribute)arr[0]).Description);
                }
            }

            return nvc;

        }


        public static byte[] GetEncodingBytes(string command)
        {
            if(!string.IsNullOrEmpty(command))
            {
                return System.Text.UTF8Encoding.ASCII.GetBytes(command);
            }
            return null;
        }
    }
}
